﻿using NLog;

namespace OpenAiMobile.Util.Log
{
    internal static class LogHelper
    {
        //是否启用debug模式
        public static bool IsDebugEnabled => _logger?.IsDebugEnabled ?? false;

        //NLog日志对象
        private static Logger _logger;

        /// <summary>
        /// 初始化日志组件
        /// </summary>
        public static void Startup()
        {
            LogManager.Setup().RegisterMauiLog().LoadConfigurationFromAssemblyResource(typeof(LogHelper).Assembly);
            _logger = LogManager.Setup().RegisterMauiLog()
                .LoadConfiguration(c => c.ForLogger(LogLevel.Debug).WriteToMauiLog())
                .GetCurrentClassLogger();
        }

        /// <summary>
        /// 关闭日志组件
        /// </summary>
        public static void Shutdown()
        {
            _logger = null;
            LogManager.Shutdown();
        }

        #region 添加日志

        public static void Trace(object value)
        {
            _logger?.Trace(value);
        }

        public static void Debug(object value)
        {
            _logger?.Debug(value);
        }

        public static void Info(object value)
        {
            _logger?.Info(value);
        }

        public static void Warn(object value)
        {
            _logger?.Warn(value);
        }

        public static void Error(object value)
        {
            _logger?.Error(value);
        }

        public static void Fatal(object value)
        {
            _logger?.Fatal(value);
        }

        #endregion
    }
}
